
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>微信扫码支付 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="appPay.html" />
    
    
    <link rel="prev" href="wechatPay.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../../">
            
                <a href="../../../">
            
                    
                    项目导航
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../../contact.html">
            
                <a href="../../contact.html">
            
                    
                    联系方式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../../study.html">
            
                <a href="../../study.html">
            
                    
                    学习资料
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../../gitchat.html">
            
                <a href="../../gitchat.html">
            
                    
                    GitChat交流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../../blog/">
            
                <a href="../../blog/">
            
                    
                    我的博客
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../../opensource/">
            
                <a href="../../opensource/">
            
                    
                    开源项目
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../../opensource/IJPay.html">
            
                <a href="../../opensource/IJPay.html">
            
                    
                    What is a IJPay?
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../../opensource/JPay.html">
            
                <a href="../../opensource/JPay.html">
            
                    
                    Android支付SDK-JPay
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../../opensource/weixin_guide.html">
            
                <a href="../../opensource/weixin_guide.html">
            
                    
                    极速开发微信公众号
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../">
            
                <a href="../">
            
                    
                    IJPay 文档
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../../IJPay-Demo.html">
            
                <a href="../../IJPay-Demo.html">
            
                    
                    IJPay-Demo
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../alipay/">
            
                <a href="../alipay/">
            
                    
                    支付宝支付
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.2.1" data-path="../alipay/alipay-config.html">
            
                <a href="../alipay/alipay-config.html">
            
                    
                    配置应用环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2.2" data-path="../alipay/alipay-init.html">
            
                <a href="../alipay/alipay-init.html">
            
                    
                    IJPay 支付宝初始化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2.3" data-path="../alipay/alipay-wap.html">
            
                <a href="../alipay/alipay-wap.html">
            
                    
                    支付宝手机网站支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2.4" data-path="../alipay/alipay-pc.html">
            
                <a href="../alipay/alipay-pc.html">
            
                    
                    支付宝电脑网站支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2.5" data-path="../alipay/alipay-offline.html">
            
                <a href="../alipay/alipay-offline.html">
            
                    
                    当面付
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.2.5.1" data-path="../alipay/alipay-offline/alipay-qrPay.html">
            
                <a href="../alipay/alipay-offline/alipay-qrPay.html">
            
                    
                    支付宝扫码支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2.5.2" data-path="../alipay/alipay-offline/alipay-barPay.html">
            
                <a href="../alipay/alipay-offline/alipay-barPay.html">
            
                    
                    支付宝条码支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2.5.3" data-path="../alipay/alipay-offline/alipay-wavePay.html">
            
                <a href="../alipay/alipay-offline/alipay-wavePay.html">
            
                    
                    支付宝声波支付
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7.2.6" data-path="../alipay/alipay-coupon.html">
            
                <a href="../alipay/alipay-coupon.html">
            
                    
                    支付宝红包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2.7" data-path="../alipay/alipay-transfer.html">
            
                <a href="../alipay/alipay-transfer.html">
            
                    
                    支付宝提现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2.8" data-path="../alipay/alipay-app.html">
            
                <a href="../alipay/alipay-app.html">
            
                    
                    支付宝APP支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2.9" data-path="../alipay/alipay-notify.html">
            
                <a href="../alipay/alipay-notify.html">
            
                    
                    支付宝服务端异步通知
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2.10" data-path="../alipay/alipay-api.html">
            
                <a href="../alipay/alipay-api.html">
            
                    
                    支付宝API字典
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="./">
            
                <a href="./">
            
                    
                    微信支付
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.3.1" data-path="wxapi.html">
            
                <a href="wxapi.html">
            
                    
                    微信公用API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3.2" data-path="allapi.html">
            
                <a href="allapi.html">
            
                    
                    微信支付API接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3.3" data-path="micropay.html">
            
                <a href="micropay.html">
            
                    
                    微信刷卡支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3.4" data-path="wechatPay.html">
            
                <a href="wechatPay.html">
            
                    
                    微信公众号支付
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.7.3.5" data-path="qrPay.html">
            
                <a href="qrPay.html">
            
                    
                    微信扫码支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3.6" data-path="appPay.html">
            
                <a href="appPay.html">
            
                    
                    微信APP支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3.7" data-path="H5.html">
            
                <a href="H5.html">
            
                    
                    微信H5支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3.8" data-path="wxapp.html">
            
                <a href="wxapp.html">
            
                    
                    微信小程序支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3.9" data-path="redpack.html">
            
                <a href="redpack.html">
            
                    
                    微信现金红包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3.10" data-path="transfers.html">
            
                <a href="transfers.html">
            
                    
                    微信企业付款
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3.11" data-path="refund.html">
            
                <a href="refund.html">
            
                    
                    微信退款
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3.12" data-path="wxpay-notify.html">
            
                <a href="wxpay-notify.html">
            
                    
                    服务端异步通知
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../.." >微信扫码支付</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h3 id="&#x6587;&#x6863;&#x535A;&#x5BA2;">&#x6587;&#x6863;&amp;&#x535A;&#x5BA2;</h3>
<p><a href="https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_1" target="_blank">&#x5FAE;&#x4FE1;&#x626B;&#x7801;&#x652F;&#x4ED8;&#x5B98;&#x65B9;&#x6587;&#x6863;</a><br><a href="http://blog.csdn.net/zyw_java/article/details/54024162" target="_blank">&#x5FAE;&#x4FE1;&#x5F00;&#x53D1;&#x4E4B;&#x626B;&#x7801;&#x652F;&#x4ED8;</a></p>
<h3 id="&#x626B;&#x7801;&#x652F;&#x4ED8;&#x6A21;&#x5F0F;&#x4ECB;&#x7ECD;">&#x626B;&#x7801;&#x652F;&#x4ED8;&#x6A21;&#x5F0F;&#x4ECB;&#x7ECD;</h3>
<ul>
<li>&#x6A21;&#x5F0F;&#x4E00;<blockquote>
<p>&#x6A21;&#x5F0F;&#x4E00;&#x5F00;&#x53D1;&#x524D;&#xFF0C;&#x5546;&#x6237;&#x5FC5;&#x987B;&#x5728;&#x516C;&#x4F17;&#x5E73;&#x53F0;&#x540E;&#x53F0;&#x8BBE;&#x7F6E;&#x652F;&#x4ED8;&#x56DE;&#x8C03;URL&#x3002;URL&#x5B9E;&#x73B0;&#x7684;&#x529F;&#x80FD;&#xFF1A;<strong>&#x63A5;&#x6536;&#x7528;&#x6237;&#x626B;&#x7801;&#x540E;&#x5FAE;&#x4FE1;&#x652F;&#x4ED8;&#x7CFB;&#x7EDF;&#x56DE;&#x8C03;&#x7684;productid&#x548C;openid</strong>&#xFF1B;URL&#x8BBE;&#x7F6E;&#x8BE6;&#x89C1;<a href="https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_3" target="_blank">&#x56DE;&#x8C03;&#x5730;&#x5740;&#x8BBE;&#x7F6E;</a>&#x3002;</p>
</blockquote>
</li>
<li>&#x6A21;&#x5F0F;&#x4E8C;<blockquote>
<p>&#x6A21;&#x5F0F;&#x4E8C;&#x4E0E;&#x6A21;&#x5F0F;&#x4E00;&#x76F8;&#x6BD4;&#xFF0C;&#x6D41;&#x7A0B;&#x66F4;&#x4E3A;&#x7B80;&#x5355;&#xFF0C;&#x4E0D;&#x4F9D;&#x8D56;&#x8BBE;&#x7F6E;&#x7684;&#x56DE;&#x8C03;&#x652F;&#x4ED8;URL&#x3002;&#x5546;&#x6237;&#x540E;&#x53F0;&#x7CFB;&#x7EDF;&#x5148;&#x8C03;&#x7528;&#x5FAE;&#x4FE1;&#x652F;&#x4ED8;&#x7684;<strong>&#x7EDF;&#x4E00;&#x4E0B;&#x5355;&#x63A5;&#x53E3;</strong>&#xFF0C;&#x5FAE;&#x4FE1;&#x540E;&#x53F0;&#x7CFB;&#x7EDF;&#x8FD4;&#x56DE;&#x94FE;&#x63A5;&#x53C2;&#x6570;code_url&#xFF0C;&#x5546;&#x6237;&#x540E;&#x53F0;&#x7CFB;&#x7EDF;&#x5C06;code_url&#x503C;&#x751F;&#x6210;&#x4E8C;&#x7EF4;&#x7801;&#x56FE;&#x7247;&#xFF0C;&#x7528;&#x6237;&#x4F7F;&#x7528;&#x5FAE;&#x4FE1;&#x5BA2;&#x6237;&#x7AEF;&#x626B;&#x7801;&#x540E;&#x53D1;&#x8D77;&#x652F;&#x4ED8;&#x3002;&#x6CE8;&#x610F;&#xFF1A;code_url&#x6709;&#x6548;&#x671F;&#x4E3A;2&#x5C0F;&#x65F6;&#xFF0C;&#x8FC7;&#x671F;&#x540E;&#x626B;&#x7801;&#x4E0D;&#x80FD;&#x518D;&#x53D1;&#x8D77;&#x652F;&#x4ED8;&#x3002;</p>
</blockquote>
</li>
</ul>
<p>&#x6A21;&#x5F0F;&#x4E00;&#x4E0E;&#x6A21;&#x5F0F;&#x4E8C;&#x7684;&#x533A;&#x522B;</p>
<ul>
<li><p>&#x4E8C;&#x7EF4;&#x7801;&#x751F;&#x6210;&#x573A;&#x666F;&#x4E0D;&#x540C;</p>
<blockquote>
<p>&#x6A21;&#x5F0F;&#x4E00;&#x662F;&#x6839;&#x636E;&#x5FAE;&#x4FE1;&#x652F;&#x4ED8;&#x89C4;&#x5B9A;&#x683C;&#x5F0F;&#x751F;&#x6210;&#x4E8C;&#x7EF4;&#x7801;&#x5C55;&#x793A;&#x7ED9;&#x7528;&#x6237;&#x626B;&#x7801;&#xFF0C;&#x6A21;&#x5F0F;&#x4E8C;&#x662F;&#x901A;&#x8FC7;&#x7EDF;&#x4E00;&#x4E0B;&#x5355;&#x751F;&#x6210;&#x9884;&#x4ED8;&#x8BA2;&#x5355;&#x4EE5;&#x53CA;code_url&#x5176;&#x4E2D;code_url&#x5C31;&#x662F;&#x751F;&#x6210;&#x4E8C;&#x7EF4;&#x7801;&#x7684;URL&#x3002;</p>
</blockquote>
</li>
<li><p>&#x6388;&#x6743;&#x83B7;&#x53D6;&#x7528;&#x6237;openId</p>
<blockquote>
<p>&#x6A21;&#x5F0F;&#x4E00;&#x4E0D;&#x9700;&#x8981;&#x800C;&#x6A21;&#x5F0F;&#x4E8C;&#x9700;&#x8981;&#x6388;&#x6743;&#x83B7;&#x53D6;&#x7528;&#x6237;&#x7684;openId</p>
</blockquote>
</li>
<li><p>&#x4E8C;&#x7EF4;&#x7801;&#x6709;&#x6548;&#x671F;</p>
</li>
</ul>
<blockquote>
<p>&#x6A21;&#x5F0F;&#x4E00;&#x6C38;&#x4E45;&#x6709;&#x6548;&#x800C;&#x6A21;&#x5F0F;&#x4E8C;&#x6709;&#x6548;&#x671F;&#x4E3A;2&#x5C0F;&#x65F6;</p>
</blockquote>
<h3 id="&#x63A5;&#x5165;&#x6B65;&#x9AA4;">&#x63A5;&#x5165;&#x6B65;&#x9AA4;</h3>
<ul>
<li><p>&#x6A21;&#x5F0F;&#x4E00;</p>
<blockquote>
<ol>
<li>&#x6839;&#x636E;&#x5FAE;&#x4FE1;&#x751F;&#x6210;&#x4E8C;&#x7EF4;&#x7801;&#x89C4;&#x5219;&#x751F;&#x6210;&#x4E8C;&#x7EF4;&#x7801;</li>
<li>&#x56DE;&#x8C03;&#x5546;&#x6237;&#x652F;&#x4ED8;URL</li>
<li>&#x8C03;&#x7528;&#x7EDF;&#x4E00;&#x4E0B;&#x5355;&#x63A5;&#x53E3;&#x63D0;&#x4EA4;&#x652F;&#x4ED8;&#x4EA4;&#x6613;</li>
<li>&#x5904;&#x7406;&#x652F;&#x4ED8;&#x7ED3;&#x679C;</li>
</ol>
</blockquote>
</li>
<li><p>&#x6A21;&#x5F0F;&#x4E8C;</p>
<blockquote>
<ol>
<li>&#x6388;&#x6743;&#x83B7;&#x53D6;&#x7528;&#x6237;&#x7684;openId</li>
<li>&#x8C03;&#x7528;&#x7EDF;&#x4E00;&#x4E0B;&#x5355;&#x63A5;&#x53E3;&#x751F;&#x6210;&#x9884;&#x652F;&#x4ED8;&#x4EA4;&#x6613;</li>
<li>&#x6839;&#x636E;&#x7EDF;&#x4E00;&#x4E0B;&#x5355;&#x63A5;&#x53E3;&#x8FD4;&#x56DE;code_url&#x751F;&#x6210;&#x4E8C;&#x7EF4;&#x7801;</li>
<li>&#x5904;&#x7406;&#x652F;&#x4ED8;&#x7ED3;&#x679C;</li>
</ol>
</blockquote>
</li>
</ul>
<h3 id="&#x751F;&#x6210;&#x4E8C;&#x7EF4;&#x7801;">&#x751F;&#x6210;&#x4E8C;&#x7EF4;&#x7801;</h3>
<blockquote>
<p>&#x6A21;&#x5F0F;&#x4E00;</p>
</blockquote>
<pre><code>//&#x6839;&#x636E;&#x751F;&#x6210;&#x4E8C;&#x7EF4;&#x7801;&#x89C4;&#x5219;&#x751F;&#x6210;&#x4E8C;&#x7EF4;&#x7801;URL
String qrCodeUrl=WxPayApi.getCodeUrl(config.getAppId(), config.getMchId(),product_id, config.getPaternerKey(), true);
//&#x4F7F;&#x7528;&#x7B2C;&#x4E09;&#x65B9;&#x5DE5;&#x5177;&#x751F;&#x6210;&#x4E8C;&#x7EF4;&#x7801;
ZxingKit.encode(qrCodeUrl, BarcodeFormat.QR_CODE, 3, ErrorCorrectionLevel.H, &quot;png&quot;, 200, 200,        PathKit.getWebRootPath()+File.separator+name );
</code></pre><p>&#x751F;&#x6210;&#x4E8C;&#x7EF4;&#x7801;&#x5177;&#x4F53;&#x5B9E;&#x73B0;</p>
<pre><code>    /**
     * &#x626B;&#x7801;&#x6A21;&#x5F0F;&#x4E00;&#x4E4B;&#x751F;&#x6210;&#x4E8C;&#x7EF4;&#x7801;
     * 
     * @param appid
     * @param mch_id
     * @param product_id
     * @param partnerKey
     * @param isToShortUrl
     *            &#x662F;&#x5426;&#x8F6C;&#x5316;&#x4E3A;&#x77ED;&#x8FDE;&#x63A5;
     * @return {String}
     */
    public static String getCodeUrl(String appid, String mch_id, String product_id, String partnerKey,
            boolean isToShortUrl) {
        String url = &quot;weixin://wxpay/bizpayurl?sign=XXXXX&amp;appid=XXXXX&amp;mch_id=XXXXX&amp;product_id=XXXXX&amp;time_stamp=XXXXX&amp;nonce_str=XXXXX&quot;;
        String timeStamp = Long.toString(System.currentTimeMillis() / 1000);
        String nonceStr = Long.toString(System.currentTimeMillis());
        Map&lt;String, String&gt; packageParams = new HashMap&lt;String, String&gt;();
        packageParams.put(&quot;appid&quot;, appid);
        packageParams.put(&quot;mch_id&quot;, mch_id);
        packageParams.put(&quot;product_id&quot;, product_id);
        packageParams.put(&quot;time_stamp&quot;, timeStamp);
        packageParams.put(&quot;nonce_str&quot;, nonceStr);
        String packageSign = PaymentKit.createSign(packageParams, partnerKey);
        String qrCodeUrl = PaymentKit.replace(url, &quot;XXXXX&quot;, packageSign, appid, mch_id, product_id, timeStamp,
                nonceStr);
        if (isToShortUrl) {
            String shortResult = WxPayApi
                    .toShortUrl(PaymentKit.buildShortUrlParasMap(appid, null, mch_id, null, qrCodeUrl, partnerKey));
            Map&lt;String, String&gt; shortMap = PaymentKit.xmlToMap(shortResult);
            String return_code = shortMap.get(&quot;return_code&quot;);
            if (PaymentKit.codeIsOK(return_code)) {
                String result_code = shortMap.get(&quot;result_code&quot;);
                if (PaymentKit.codeIsOK(result_code)) {
                    qrCodeUrl = shortMap.get(&quot;short_url&quot;);
                }
            }
        }

        return qrCodeUrl;
    }
</code></pre><blockquote>
<p>&#x6A21;&#x5F0F;&#x4E8C;</p>
</blockquote>
<p>&#x6A21;&#x5F0F;&#x4E8C;&#x751F;&#x6210;&#x4E8C;&#x7EF4;&#x7801;&#x6B65;&#x9AA4;&#x8BF7;&#x53C2;&#x8003;<code>&#x516C;&#x7528;API</code>&#x4E2D;&#x7684;&#x7EDF;&#x4E00;&#x4E0B;&#x5355;&#x63A5;&#x53E3;&#xFF0C;&#x793A;&#x4F8B;&#x4EE3;&#x7801;&#x8BF7;&#x53C2;&#x8003;<br>&#x4E0B;&#x6587;<code>&#x4EE3;&#x7801;&#x793A;&#x4F8B;</code></p>
<h3 id="&#x4EE3;&#x7801;&#x793A;&#x4F8B;">&#x4EE3;&#x7801;&#x793A;&#x4F8B;</h3>
<p><a href="https://gitee.com/javen205/IJPay-Demo" target="_blank">https://gitee.com/javen205/IJPay-Demo</a></p>
<blockquote>
<p>&#x6A21;&#x5F0F;&#x4E00;</p>
</blockquote>
<pre><code>    /**
     * &#x751F;&#x6210;&#x652F;&#x4ED8;&#x4E8C;&#x7EF4;&#x7801;&#xFF08;&#x6A21;&#x5F0F;&#x4E00;&#xFF09;&#x5E76;&#x5728;&#x9875;&#x9762;&#x4E0A;&#x663E;&#x793A;
     */
    public void scanCode1(){
        try {
            String product_id = getPara(&quot;productId&quot;);
            if (StrKit.isBlank(product_id)) {
                ajax.addError(&quot;productId is null&quot;);
                renderJson(ajax);
                return;
            }
            WxPayApiConfig config = WxPayApiConfigKit.getWxPayApiConfig();
            //&#x83B7;&#x53D6;&#x626B;&#x7801;&#x652F;&#x4ED8;&#xFF08;&#x6A21;&#x5F0F;&#x4E00;&#xFF09;url
            String qrCodeUrl=WxPayApi.getCodeUrl(config.getAppId(), config.getMchId(),product_id, config.getPaternerKey(), true);
            log.info(qrCodeUrl);
            //&#x751F;&#x6210;&#x4E8C;&#x7EF4;&#x7801;&#x4FDD;&#x5B58;&#x7684;&#x8DEF;&#x5F84;
            String name = &quot;payQRCode1.png&quot;;
            Boolean encode = ZxingKit.encode(qrCodeUrl, BarcodeFormat.QR_CODE, 3, ErrorCorrectionLevel.H, &quot;png&quot;, 200, 200,
                    PathKit.getWebRootPath()+File.separator+name );
            if (encode) {
                //&#x5728;&#x9875;&#x9762;&#x4E0A;&#x663E;&#x793A;
                ajax.success(name);
                renderJson(ajax);
            }
        } catch (Exception e) {
            ajax.addError(&quot;&#x7CFB;&#x7EDF;&#x5F02;&#x5E38;&#xFF1A;&quot;+e.getMessage());
            renderJson(ajax);
            e.printStackTrace();
        }
    }
</code></pre><pre><code>    /**
     * &#x626B;&#x7801;&#x652F;&#x4ED8;&#x6A21;&#x5F0F;&#x4E00;&#x56DE;&#x8C03;
     * &#x5DF2;&#x6D4B;&#x8BD5;
     */
    public void wxpay(){
        try {

            String result  = HttpKit.readData(getRequest());
            System.out.println(&quot;callBack_xml&gt;&gt;&gt;&quot;+result);
            /**
             * &#x83B7;&#x53D6;&#x8FD4;&#x56DE;&#x7684;&#x4FE1;&#x606F;&#x5185;&#x5BB9;&#x4E2D;&#x5404;&#x4E2A;&#x53C2;&#x6570;&#x7684;&#x503C;
             */
            Map&lt;String, String&gt; map = PaymentKit.xmlToMap(result);
            for (String key : map.keySet()) {
                   System.out.println(&quot;key= &quot;+ key + &quot; and value= &quot; + map.get(key));
            }

            String appid=map.get(&quot;appid&quot;);
            String openid = map.get(&quot;openid&quot;);
            String mch_id = map.get(&quot;mch_id&quot;);
            String is_subscribe = map.get(&quot;is_subscribe&quot;);
            String nonce_str = map.get(&quot;nonce_str&quot;);
            String product_id = map.get(&quot;product_id&quot;);
            String sign = map.get(&quot;sign&quot;);
            Map&lt;String, String&gt; packageParams = new HashMap&lt;String, String&gt;();
            packageParams.put(&quot;appid&quot;, appid);
            packageParams.put(&quot;openid&quot;, openid);
            packageParams.put(&quot;mch_id&quot;,mch_id);
            packageParams.put(&quot;is_subscribe&quot;,is_subscribe);
            packageParams.put(&quot;nonce_str&quot;,nonce_str);
            packageParams.put(&quot;product_id&quot;, product_id);

            String packageSign = PaymentKit.createSign(packageParams, WxPayApiConfigKit.getWxPayApiConfig().getPaternerKey());
            // &#x7EDF;&#x4E00;&#x4E0B;&#x5355;&#x6587;&#x6863;&#x5730;&#x5740;&#xFF1A;https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1


            String ip = IpKit.getRealIp(getRequest());
            if (StrKit.isBlank(ip)) {
                ip = &quot;127.0.0.1&quot;;
            }

            Map&lt;String, String&gt; params = WxPayApiConfigKit.getWxPayApiConfig()
                    .setAttach(&quot;IJPay &#x626B;&#x7801;&#x6A21;&#x5F0F;&#x4E00;&#x6D4B;&#x8BD5;  -By Javen&quot;)
                    .setBody(&quot;IJPay &#x626B;&#x7801;&#x6A21;&#x5F0F;&#x4E00;&#x6D4B;&#x8BD5;  -By Javen&quot;)
                    .setOpenId(openid)
                    .setSpbillCreateIp(ip)
                    .setTotalFee(&quot;100&quot;)
                    .setTradeType(TradeType.NATIVE)
                    .setNotifyUrl(notify_url)
                    .setOutTradeNo(String.valueOf(System.currentTimeMillis()))
                    .build();

            String xmlResult = WxPayApi.pushOrder(false,params);
            log.info(&quot;prepay_xml&gt;&gt;&gt;&quot;+xmlResult);

            /**
             * &#x53D1;&#x9001;&#x4FE1;&#x606F;&#x7ED9;&#x5FAE;&#x4FE1;&#x670D;&#x52A1;&#x5668;
             */
            Map&lt;String, String&gt; payResult = PaymentKit.xmlToMap(xmlResult);

            String return_code = payResult.get(&quot;return_code&quot;);
            String result_code = payResult.get(&quot;result_code&quot;);

            if (StrKit.notBlank(return_code) &amp;&amp; StrKit.notBlank(result_code) &amp;&amp; return_code.equalsIgnoreCase(&quot;SUCCESS&quot;)&amp;&amp;result_code.equalsIgnoreCase(&quot;SUCCESS&quot;)) {
                // &#x4EE5;&#x4E0B;&#x5B57;&#x6BB5;&#x5728;return_code &#x548C;result_code&#x90FD;&#x4E3A;SUCCESS&#x7684;&#x65F6;&#x5019;&#x6709;&#x8FD4;&#x56DE;
                String prepay_id = payResult.get(&quot;prepay_id&quot;);

                Map&lt;String, String&gt; prepayParams = new HashMap&lt;String, String&gt;();
                prepayParams.put(&quot;return_code&quot;, &quot;SUCCESS&quot;);
                prepayParams.put(&quot;appId&quot;, appid);
                prepayParams.put(&quot;mch_id&quot;, mch_id);
                prepayParams.put(&quot;nonceStr&quot;, System.currentTimeMillis() + &quot;&quot;);
                prepayParams.put(&quot;prepay_id&quot;, prepay_id);
                String prepaySign = null;
                if (sign.equals(packageSign)) {
                    prepayParams.put(&quot;result_code&quot;, &quot;SUCCESS&quot;);
                }else {
                    prepayParams.put(&quot;result_code&quot;, &quot;FAIL&quot;);
                    prepayParams.put(&quot;err_code_des&quot;, &quot;&#x8BA2;&#x5355;&#x5931;&#x6548;&quot;);   //result_code&#x4E3A;FAIL&#x65F6;&#xFF0C;&#x6DFB;&#x52A0;&#x8BE5;&#x952E;&#x503C;&#x5BF9;&#xFF0C;value&#x503C;&#x662F;&#x5FAE;&#x4FE1;&#x544A;&#x8BC9;&#x5BA2;&#x6237;&#x7684;&#x4FE1;&#x606F;
                }
                prepaySign = PaymentKit.createSign(prepayParams, WxPayApiConfigKit.getWxPayApiConfig().getPaternerKey());
                prepayParams.put(&quot;sign&quot;, prepaySign);
                String xml = PaymentKit.toXml(prepayParams);
                log.error(xml);
                renderText(xml);

            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
</code></pre><blockquote>
<p>&#x6A21;&#x5F0F;&#x4E8C;</p>
</blockquote>
<pre><code>    /**
     * &#x626B;&#x7801;&#x652F;&#x4ED8;&#x6A21;&#x5F0F;&#x4E8C;
     */
    public void scanCode2() {    
        //String openId=&quot;o5NJx1dVRilQI6uUVSaBDuLnM3iM&quot;;
        String openId = (String) getSession().getAttribute(&quot;openId&quot;);

        String total_fee=getPara(&quot;total_fee&quot;);

        if (StrKit.isBlank(openId)) {
            ajax.addError(&quot;openId is null&quot;);
            renderJson(ajax);
            return;
        }
        if (StrKit.isBlank(total_fee)) {
            ajax.addError(&quot;&#x652F;&#x4ED8;&#x91D1;&#x989D;&#x4E0D;&#x80FD;&#x4E3A;&#x7A7A;&quot;);
            renderJson(ajax);
            return;
        }

        String ip = IpKit.getRealIp(getRequest());
        if (StrKit.isBlank(ip)) {
            ip = &quot;127.0.0.1&quot;;
        }

        Map&lt;String, String&gt; params = WxPayApiConfigKit.getWxPayApiConfig()
                .setAttach(&quot;IJPay &#x6D4B;&#x8BD5;  -By Javen&quot;)
                .setBody(&quot;IJPay &#x626B;&#x7801;&#x652F;&#x4ED8;2&#x6D4B;&#x8BD5;  -By Javen&quot;)
                .setOpenId(openId)
                .setSpbillCreateIp(ip)
                .setTotalFee(total_fee)
                .setTradeType(TradeType.NATIVE)
                .setNotifyUrl(notify_url)
                .setOutTradeNo(String.valueOf(System.currentTimeMillis()))
                .build();

        String xmlResult = WxPayApi.pushOrder(false,params);

log.info(xmlResult);
        Map&lt;String, String&gt; result = PaymentKit.xmlToMap(xmlResult);

        String return_code = result.get(&quot;return_code&quot;);
        String return_msg = result.get(&quot;return_msg&quot;);
        if (!PaymentKit.codeIsOK(return_code)) {
            System.out.println(return_msg);
            renderText(xmlResult);
            return;
        }
        String result_code = result.get(&quot;result_code&quot;);
        if (!PaymentKit.codeIsOK(result_code)) {
            System.out.println(return_msg);
            renderText(xmlResult);
            return;
        }
        //&#x751F;&#x6210;&#x9884;&#x4ED8;&#x8BA2;&#x5355;success

        String qrCodeUrl = result.get(&quot;code_url&quot;);
        String name = &quot;payQRCode2.png&quot;;

        Boolean encode = ZxingKit.encode(qrCodeUrl, BarcodeFormat.QR_CODE, 3, ErrorCorrectionLevel.H, &quot;png&quot;, 200, 200,
                PathKit.getWebRootPath()+File.separator+name);
        if (encode) {
//            renderQrCode(qrCodeUrl, 200, 200);
            //&#x5728;&#x9875;&#x9762;&#x4E0A;&#x663E;&#x793A;
            ajax.success(name);
            renderJson(ajax);
        }
    }
</code></pre>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="wechatPay.html" class="navigation navigation-prev " aria-label="Previous page: 微信公众号支付">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="appPay.html" class="navigation navigation-next " aria-label="Next page: 微信APP支付">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"微信扫码支付","level":"1.7.3.5","depth":3,"next":{"title":"微信APP支付","level":"1.7.3.6","depth":3,"path":"doc/ijpay/wxpay/appPay.md","ref":"doc/ijpay/wxpay/appPay.md","articles":[]},"previous":{"title":"微信公众号支付","level":"1.7.3.4","depth":3,"path":"doc/ijpay/wxpay/wechatPay.md","ref":"doc/ijpay/wxpay/wechatPay.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"doc/ijpay/wxpay/qrPay.md","mtime":"2018-09-07T06:36:36.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-03-27T03:48:47.613Z"},"basePath":"../../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../../gitbook/gitbook.js"></script>
    <script src="../../../gitbook/theme.js"></script>
    
        
        <script src="../../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

